{include file="common/head"/}
<style>

    .ens{
        cursor: pointer;
        float: left;
        margin-top: 15px;
        margin-right: 44px;
    }
    .icon-ls{
        display: inline-block;
        border: 1px solid #ccc;
        width: 25px;
        height: 25px;
        text-align: center;
        line-height: 25px;
        color: #fff;
        /* font-size: 18px; */
        font-weight: bold;
    }
    .icon-ls-act{
        background-color: #1aa094;
    }
    #dataList{
        width: 100%;

    }
    #dataList li {
        float: left;
        width: 150px;
        height: 80px;
        margin-left: 15px;
        margin-top: 15px;
        background-color: rgba(0, 150, 136, 1);
        text-align: center;
        border-radius: 5px;
        color: #fff;
        display: -webkit-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        -webkit-box-pack: center;
        -ms-flex-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-box-align: center;
        -ms-flex-align: center;
        -webkit-align-items: center;
        align-items: center;
        position: relative;
        overflow: hidden;
        cursor: pointer;
        font-size: 15px;
    }
    #dataList li i{
        display: none;
        width: 100%;
        height: 100%;
        position: absolute;
        background: rgba(0,0,0,0.3);
        font-size: 31px;
        text-align: left;
        padding-top: 10px;
        padding-left: 10px;
    }
</style>
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>派单列表</legend>
    </fieldset>
    <div class="demoTable">
        <button class="layui-btn" data-type="reload" onclick="location.reload()">刷新</button>
        <div class="layui-inline">
            <input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}编号或关键字">
        </div>
        <button class="layui-btn" id="search" data-type="reload">{:lang('search')}</button>
        <!--<a href="{:url('queryPage')}" class="layui-btn">显示全部</a>-->
       <!-- <button type="button" class="layui-btn layui-btn-danger" id="delAll">批量关闭</button>-->

        <button type="button" class="layui-btn" id="add">创建派单任务</button>
        <button type="button" class="layui-btn layui-btn-normal" id="tak">接单列表</button>

    </div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script type="text/html" id="option">

    {{# if(gid==7){ }}
    <!--调度-->
        {{# if(d.state_id==20){ }}
        <!--等待派单-->
            {{# if(d.is_me==0){ }}
                <a class="layui-btn layui-btn-xs" lay-event="dis" >第三方派单</a>
            {{# }else{  }}
                <a class="layui-btn layui-btn-xs" lay-event="me" >派单</a>
            {{# } }}

        {{# }else if(d.state_id==23){  }}
        <!--拒绝接单-->
            {{# if(d.is_me==0){ }}
                <a class="layui-btn layui-btn-xs" lay-event="dis" >重新派单</a>
            {{# }else{  }}
                <a class="layui-btn layui-btn-xs" lay-event="me" >重新派单</a>
            {{# } }}
            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="refu_info" >拒单原因</a>

        {{# } }}

    {{# }else if(gid==9){  }}
    <!--区域经理-->
        {{# if(d.state_id==21||d.state_id==25){ }}
        <!--等待派单-->
            {{# if(d.is_team==0){ }}
                <a class="layui-btn layui-btn-xs" lay-event="qdis" >派单</a>
            {{# }else{  }}
                <a class="layui-btn layui-btn-xs" lay-event="team_meet" >团队管理</a>
            {{# } }}

        {{# }else if(d.state_id==22){  }}
        <!--已接单-->
            <a class="layui-btn layui-btn-xs" lay-event="rece" >接单</a>
            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="refu" >拒单</a>
        {{# }else if(d.state_id==23){  }}
        <!--拒绝接单-->
            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="refu_info" >拒单原因</a>
        {{# } }}
    {{# }else if(gid==6){  }}
    <!--第三方-->
        {{# if(d.state_id==21||d.state_id==25){ }}
        <!--等待派单-->
            {{# if(d.is_team==0){ }}
            <a class="layui-btn layui-btn-xs" lay-event="qdis" >派单</a>
            {{# }else{  }}
            <a class="layui-btn layui-btn-xs" lay-event="team_meet" >团队管理</a>
            {{# } }}

        {{# }else if(d.state_id==22){  }}
        <!--已接单-->
            <a class="layui-btn layui-btn-xs" lay-event="rece" >接单</a>
            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="refu" >拒单</a>
        {{# }else if(d.state_id==23){  }}
        <!--拒绝接单-->
            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="refu_info" >拒单原因</a>
        {{# } }}
    {{# }else if(gid==5 && isgroup==1){  }}
    <!--组长-->
        {{# if(d.is_conf==0){ }}
            <a class="layui-btn layui-btn-xs" lay-event="meet_a" >接单</a>
            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="meet_re" >拒单</a>
        {{# }else if(d.is_conf==1){  }}
            <!--{{# if(d.is_team==0){ }}
                <a class="layui-btn layui-btn-xs" lay-event="team" >组建团队</a>
            {{# }else{  }}
                <a class="layui-btn layui-btn-xs" lay-event="teams" lay-team="1">团队管理</a>
            {{# } }}-->

            <a class="layui-btn layui-btn-xs" lay-event="teams" lay-team="1">团队管理</a>
        {{# }else if(d.is_conf==2){  }}
            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="meet_info" >拒单原因</a>
        {{# } }}
    {{# }else if(gid==5 && isgroup==0){  }}
    <!--队员-->
        {{# if(d.is_conf==0){ }}
        <a class="layui-btn layui-btn-xs" lay-event="meet_a" >接单</a>
        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="meet_re" >拒单</a>
        {{# }else if(d.is_conf==2){  }}
        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="meet_info" >拒单原因</a>
        {{# } }}
    {{# }else{  }}

    {{# } }}



    {{# if(d.state_id==25){ }}
        <a class="layui-btn layui-btn-xs" lay-event="track" >跟踪状态</a>
    {{# } }}

    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="info" >查看详情</a>
    {{# if(apid==1){ }}
    <a class="layui-btn layui-btn-xs" lay-event="del" >删除</a>
    {{# } }}
</script>

<script type="text/html" id="state">
    {{# if(d.state_id==23){ }}

        {{# if(!d.username){ }}
            <span style="color: red">({{d.reg_name}}){{d.state_name}}</span>
        {{# }else{  }}
            <span style="color: red">({{d.name}}){{d.state_name}}</span>
        {{# } }}

    {{# }else{  }}
        {{# if(!d.reg_name){ }}
            <span>{{d.state_name}}</span>
        {{# }else{  }}
            <span>{{d.state_name}}({{d.reg_name}})</span>
        {{# } }}

    {{# } }}
</script>
<script type="text/html" id="comp">
    {{# if(d.is_comp==1){ }}
    任务结束
    {{# }else{  }}
    任务进行中
    {{# } }}
</script>
<script type="text/html" id="info">
    <a href="{:url('disInfo')}?id={{d.id}}">{{d.title}}</a>
</script>
<script type="text/html" id="no">
    <a href="{:url('disInfo')}?id={{d.id}}">{{d.number}}</a>
</script>
<script>
    var gid = '{:session("gid")}';
    var wh = {state_id:'20,21,22,23,25'};
    var apid = '{:session("aid")}';
    var isgroup = '{:session("is_group")}';


    if(gid == '6'){
        wh.admin_id = apid;
    }
    if(gid=='9'){
        wh.reg_id = apid;
    }
    let url = '{:url("queryPage")}';
    if(gid=='5'){
        url = '{:url("queryDis")}';
    }

    var $ = null;
    layui.use(['table','element'], function() {
        var table = layui.table,element = layui.element;
        $ = layui.jquery;
        var tableIn = table.render({
            id: 'works',
            elem: '#list',
            url: url,
            method: 'post',
            where:wh,
            page: true,
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'number', title: '工单号', width: 155,fixed: true,toolbar:'#no'},
                {field: 'title', title: '标题', width: 200,toolbar:'#info'},
                {field: 'tel', title: '{:lang("tel")}', width: 150},
                {field: 'desc', title: '描述', width: 300},
                {field: 'address', title: '地址', width: 150},
                {field: 'fault_name', title: '故障类型', width: 150},
                {field: 'state_name', title: '状态', width: 150,toolbar:'#state'},
                {field: 'is_comp', title: '完成', width: 120,toolbar:'#comp'},
                {width: 280, align: 'center', toolbar: '#option'}
            ]],
            limit: 10 //每页默认显示的数量
        });
        //工程师、区域经理、调度有创建工单
        if(gid != '6' && gid !='9' && gid !='7'){
            $('#add').hide();
        }
        //搜索
        $('#search').on('click', function () {
            var key = $('#key').val();
            if ($.trim(key) === '') {
                layer.msg('{:lang("pleaseEnter")}关键字！', {icon: 0});
                return;
            }
            var ck = wh;
            ck.key = key;
            ck.page = 1;
            tableIn.reload({
                where: ck,
                page:1
            });
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'dis') {
                //派单
                $.post('{:url("Person/query")}',{gid:6},function (udata) {

                    var str = '<div id="eng" style="line-height: 45px;font-size: 17px;"><span>第三方：</span>' +
                        '<select name="aid" id="aid" style="padding: 5px 15px;">';

                    $.each(udata.data,function (k,v) {
                        str += '<option value="'+v.admin_id+'">'+v.username+'</option>';
                    });

                    str +='</select>'+
                        '</div>';
                    layer.confirm('您确定要派单给第三方吗？'+str, function(index){

                        var aid = $('#aid').val();

                        if(aid.length<=0) {
                            layer.msg('请选择第三方',{icon:5});
                            return;
                        }

                        var loading = layer.load(1, {shade: [0.1, '#fff']});
                        $.post("{:url('dis')}",{id:data.id,aid:aid},function(res){
                            layer.close(loading);
                            if(res.code===1){
                                layer.msg(res.msg,{time:1000,icon:1});
                                tableIn.reload();
                            }else{
                                layer.msg(res.msg,{time:1000,icon:2});
                            }
                        });
                        layer.close(index);
                    });
                });
            }else if(obj.event === 'me'){
                $.post('{:url("Person/query")}',{gid:9},function (udata) {

                    var str = '<div id="eng" style="line-height: 45px;font-size: 17px;"><span>区域经理：</span>' +
                        '<select name="aid" id="aid" style="padding: 5px 15px;">';

                    str += '<option value="0">自主接单</option>';
                    $.each(udata.data,function (k,v) {
                        str += '<option value="'+v.admin_id+'">'+v.username+'</option>';
                    });

                    str +='</select>'+
                        '</div>';
                    layer.confirm('您确定要派单给平台区域经理吗？'+str, function(index){

                        var aid = $('#aid').val();

                        if(aid.length<=0) {
                            layer.msg('请选择区域经理',{icon:5});
                            return;
                        }

                        var loading = layer.load(1, {shade: [0.1, '#fff']});
                        $.post("{:url('disToEngin')}",{id:data.id,aid:aid},function(res){
                            layer.close(loading);
                            if(res.code===1){
                                layer.msg(res.msg,{time:1000,icon:1});
                                tableIn.reload();
                            }else{
                                layer.msg(res.msg,{time:1000,icon:2});
                            }
                        });
                        layer.close(index);
                    });
                });
            }
            else if(obj.event == 'rece'){
                //接单
                layer.confirm('您确定要接单吗？', function(index){

                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('receipt')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
            else if(obj.event == 'refu'){
                //拒单
                layer.prompt({
                    formType: 2,
                    value: '',
                    title: '请输入拒绝原因',
                    area: ['500px', '250px'] //自定义文本域宽高
                }, function(value, index, elem){

                    if(value.length<=0){
                        layer.msg('请输入原因',{icon:5});
                        return;
                    }

                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('refusal')}",{id:data.id,val:value},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });

                    layer.close(index);
                });
            }
            else if(obj.event == 'refu_info'){
                //拒绝原因
                layer.open({
                    title: '拒绝原因'
                    ,content: data.reason
                });
            }
            else if(obj.event == 'info'){
                //查看详情
                var str = '<table class="layui-table">';

                str+=   '<tr>' +
                        '<th>标题</th>'+
                        '<td>'+data.title+'</td>'+
                        '</tr>';
                str+=   '<tr>' +
                    '<th>电话</th>'+
                    '<td>'+data.tel+'</td>'+
                    '</tr>';

                str+=   '<tr>' +
                    '<th>地址</th>'+
                    '<td>'+data.address+'</td>'+
                    '</tr>';

                str+=   '<tr>' +
                    '<th>故障类型</th>'+
                    '<td>'+data.fault_name+'</td>'+
                    '</tr>';
                str+=   '<tr>' +
                    '<th>描述</th>'+
                    '<td>'+data.desc+'</td>'+
                    '</tr>';
                str+=   '<tr>' +
                    '<th>创建时间</th>'+
                    '<td>'+data.c_time+'</td>'+
                    '</tr>';

                if(data.ticket.length>0){
                    let term = new Array();
                    term = data.ticket.split(';');
                    let asc = '';
                    for(let i=0;i<term.length;i++){
                        asc += '<a href="'+term[i]+'" target="_blank" style="color: blue">工作票'+(i+1)+'</a>';
                    }
                    str+=   '<tr>' +
                        '<th>工作票</th>'+
                        '<td>'+
                        asc
                        +'</td>'+
                        '</tr>';
                }

                var att1 = '';
                var att2 = '';
                if(data.w_attach&&data.w_attach.length>0){
                    att1 = '<a href="'+data.w_attach+'" target="_blank" style="color: blue">附件1</a>';
                }
                if(data.attach&&data.attach.length>0){
                    att2 = '  <a href="'+data.attach+'" target="_blank" style="color: blue">附件2</a>';
                }
                str+=   '<tr>' +
                    '<th>附件</th>'+
                    '<td>'+att1+att2+'</td>'+
                    '</tr>';
                if(data.state_id==23){
                    str+=   '<tr>' +
                        '<th>拒单原因</th>'+
                        '<td>('+data.username+')'+data.reason+'</td>'+
                        '</tr>';
                }


                if(data.arge.length>0){
                    let term = new Array();
                    term = data.arge.split(';');
                    let asc = '';
                    for(let i=0;i<term.length;i++){
                        asc += '<a href="'+term[i]+'" target="_blank" style="color: blue">协议单'+(i+1)+'</a>';
                    }
                    str+=   '<tr>' +
                        '<th>完成协议单</th>'+
                        '<td>'+asc+'</td>'+
                        '</tr>';
                }

                str += '</table>';
                layer.open({
                    title:'详情',
                    area:['540px','460px'],
                    content:str,
                });
            }
            else if(obj.event == 'team'){
                //组建团队
                /*$.post('{:url("Engin/query")}',{apid:apid,gid:'5'},function (dal) {
                    var str = '<div id="enList" style="margin-left: 20px;">';
                    str += '<ul class="ps">';
                    //icon-ls-act
                    $.each(dal.data,function(k,v){
                        str += '<li class="ens" aid="'+v.admin_id+'" isc="0" at="'+v.is_at+'"><span class="icon-ls"><i class="layui-icon layui-icon-ok"></i></span><span>'+v.jobs_title+'：</span><span style="font-size: 16px;">'+v.username+'</span><span style="color: #5fb878">('+(v.is_at==0?'空闲':'工作中')+')</span></li>';
                    });

                    str += '</ul>';
                    str += '</div>';

                    layer.open({
                        title:'组建团队',
                        type:1,
                        area:['540px','460px'],
                        btn:['提交','取消'],
                        content:str,
                        yes:function (index) {
                            var ids = '';
                            $('.ens[isc=1]').each(function () {
                                ids += $(this).attr('aid')+',';
                            });
                            if(ids.length<=0){
                                layer.msg('请选择人员',{icon:5});
                                return;
                            }
                            var loading = layer.load(1, {shade: [0.1, '#fff']});
                            $.post('{:url("team")}',{dis_id:data.id,aid:ids},function (res) {
                                layer.close(loading);
                                if(res.code===1){
                                    layer.msg(res.msg,{time:1000,icon:1});
                                    tableIn.reload();
                                }else{
                                    layer.msg(res.msg,{time:1000,icon:2});
                                }
                                layer.close(index);
                            });
                        },
                        success:function (lay,index) {
                            $('.ens').click(function(){
                                var at = $(this).attr('at');
                                if(at=='1'){
                                    layer.msg('该人员正在工作中！',{icon:5});
                                    return;
                                }
                                var isc = $(this).attr('isc');
                                var aid = $(this).attr('aid');
                                if(isc=='0'){
                                    $(this).attr('isc','1');
                                    $(this).find('.icon-ls').addClass('icon-ls-act');
                                }else{
                                    $(this).attr('isc','0');
                                    $(this).find('.icon-ls').removeClass('icon-ls-act');
                                }
                            });
                        }
                    });
                });*/
            }
            else if(obj.event == 'teams'){

                //团队人员
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post('{:url("teamList")}',{dis_id:data.id},function (re) {
                    layer.close(loading);

                    var str = '';

                    str += '<div style="border-bottom: 1px solid #ccc;line-height: 45px;padding-left: 20px;"><button class="layui-btn layui-btn-sm" id="addtr">' +
                        '  <i class="layui-icon">&#xe608;</i> 添加人员' +
                        '</button></div>';

                    str += '<table class="layui-table" style="width: 96%;margin-left: 10px;">';

                    $.each(re.data,function (k,v) {
                        str+=   '<tr>' +
                            '<th>'+v.jobs_title+'</th>'+
                            '<td>'+(v.is_lead==1?v.username+'<span style="color: #00B83F">(组长)</span>':v.username)+'</td>'+
                            '<td>' + '</td>'+
                            '</tr>';

                        if(v.children.length>0){
                            $.each(v.children,function (kl,vl) {
                                str+=   '<tr>' +
                                    '<th>|—'+vl.jobs_title+'</th>'+
                                    '<td>'+vl.username+'<span style="color: #00B83F">(组员)</span></td>'+
                                    '<td>';
                                if(vl.apid==apid)
                                str += '<a class="layui-btn layui-btn-sm moves" aid="'+vl.admin_id+'" did="'+data.id+'">移除</a>';

                                 str +=   '</td>'+
                                    '</tr>';
                            });
                        }
                    });

                    str += '</table>';
                    layer.open({
                        title:'团队人员',
                        type:1,
                        area:['540px','460px'],
                        btn:['关闭'],
                        content:str,
                        success:function (lay,index) {
                            $('#addtr').click(function () {
                                $.post('{:url("Engin/teams")}',{aid:apid},function (dal) {
                                    var str = '<div id="enList" style="margin-left: 20px;">';
                                    str += '<ul class="ps">';
                                    //icon-ls-act
                                    $.each(dal.data, function (k, v) {
                                        if(!sea(re.data,v.admin_id))
                                        str += '<li class="ens" aid="' + v.admin_id + '" isc="0" at="'+v.is_at+'"><span class="icon-ls"><i class="layui-icon layui-icon-ok"></i></span><span>' + v.jobs_title + '：</span><span style="font-size: 16px;">' + v.username + '</span><span style="color: #5fb878">(' + (v.is_at == 0 ? '空闲' : '工作中') + ')</span></li>';
                                    });

                                    str += '</ul>';
                                    str += '</div>';

                                    layer.open({
                                        title: '添加队员',
                                        type: 1,
                                        tipsMore: true,
                                        area: ['540px', '460px'],
                                        btn: ['提交', '取消'],
                                        content: str,
                                        yes: function (index2) {
                                            var ids = '';
                                            $('.ens[isc=1]').each(function () {
                                                ids += $(this).attr('aid') + ',';
                                            });
                                            if (ids.length <= 0) {
                                                layer.msg('请选择人员', {icon: 5});
                                                return;
                                            }

                                            var loading = layer.load(1, {shade: [0.1, '#fff']});

                                            $.post('{:url("addTeam")}', {dis_id: data.id, aid: ids}, function (res) {
                                                layer.close(loading);
                                                if (res.code === 1) {
                                                    layer.msg(res.msg, {time: 1000, icon: 1});
                                                    tableIn.reload();
                                                } else {
                                                    layer.msg(res.msg, {time: 1000, icon: 2});
                                                }
                                                layer.close(index2);
                                                layer.close(index);
                                            });
                                        },
                                        success: function (lay, index) {
                                            $('.ens').click(function () {
                                                var at = $(this).attr('at');
                                                if(at=='1'){
                                                    layer.msg('该人员正在工作中！',{icon:5});
                                                    return;
                                                }
                                                var isc = $(this).attr('isc');
                                                var aid = $(this).attr('aid');
                                                if (isc == '0') {
                                                    $(this).attr('isc', '1');
                                                    $(this).find('.icon-ls').addClass('icon-ls-act');
                                                } else {
                                                    $(this).attr('isc', '0');
                                                    $(this).find('.icon-ls').removeClass('icon-ls-act');
                                                }
                                            });
                                        }
                                    });
                                })
                            });
                            
                            $('.moves').click(function () {
                                var aid = $(this).attr('aid');
                                var did = $(this).attr('did');
                                var tr = $(this).parent().parent();
                                layer.confirm('确认移除该人员吗?', {icon: 3, title:'提示'}, function(rin){
                                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                                    $.post('{:url("remove")}',{dis_id:did,aid:aid},function (re) {
                                        layer.close(loading);
                                        if (re.code === 1) {
                                            layer.msg(re.msg, {time: 1000, icon: 1});
                                            tr.remove();
                                        } else {
                                            layer.msg(re.msg, {time: 1000, icon: 2});
                                        }
                                        layer.close(rin);
                                        layer.close(index);
                                    });
                                });
                            });
                            $('.lead').click(function () {
                                var aid = $(this).attr('aid');
                                var did = $(this).attr('did');
                                var tr = $(this).parent().parent();
                                layer.confirm('确认将该人员提升为领队吗?（提示：已有领队成为普通队员）', {icon: 3, title:'提示'}, function(lin){
                                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                                    $.post('{:url("lead")}',{did:did,aid:aid},function (re) {
                                        layer.close(loading);
                                        if (re.code === 1) {
                                            layer.msg(re.msg, {time: 1000, icon: 1});
                                        } else {
                                            layer.msg(re.msg, {time: 1000, icon: 2});
                                        }
                                        layer.close(lin);
                                        layer.close(index);
                                    });
                                });
                            });
                        }
                    });

                });

            }
            else if(obj.event == 'track'){


                //这里重新修改

                $.post('{:url("track")}',{dis_id:data.id},function (data) {
                    let str = '<div class="layui-card-body"><div class="layui-collapse" id="tab_list">';
                    $.each(data.data,function (k,v) {
                         str += '<div class="layui-colla-item">\n' +
                            '    <h2 class="layui-colla-title">'+v.title+'('+v.admin_name+(v.is_comp==1?'-<span style="color: green">已完成</span>':'-<span style="color: red">正在进行</span>')+')-'+v.add_time+'</h2>\n' +
                            '    <div class="layui-colla-content '+(k==0?'layui-show':'')+'" style="padding: 3px 10px;">\n';

                        str += '<table class="layui-table"><tbody>';
                        $.each(v.list,function (kl,vl) {
                            str += '<tr><td class="text-center"><img src="'+vl.icon+'" alt="" style="max-width: 22px;"></td><td>'+'【'+vl.admin_name+'】'+vl.content+expl(vl.attach)+'<br><span style="font-size: 14px;color: #999">'+vl.c_time+'</span></td></tr>';
                        });
                        str += '</tbody></table>';

                        str += '    </div>\n' +
                            '</div>';
                    });
                    str += '</div></div>';
                    layer.open({
                        title:'任务跟踪',
                        btn:['关闭'],
                        area:['700px','570px'],
                        content:str,
                    });
                    element.render();
                });

            }
            else if(obj.event == 'comp'){
                layer.confirm('您确定要结束任务单吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('comp')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
            else if(obj.event == 'qdis'){//区域经理派单
                $.post('{:url("Person/query")}',{gid:5,is_group:1},function (udata) {

                    var str = '<div id="eng" style="width: 100%;height: 100%;overflow: auto;">' +
                        '<ul id="dataList">';

                    $.each(udata.data,function (k,v) {
                        str += '<li class="tar-i" ised="0" value="'+v.admin_id+'">'+v.username+'('+v.name+')'+'<i class="layui-icon">&#x1005;</i></li>';
                    });

                    str +='</ul>'+
                        '</div>';
                    layer.open({
                        title:'派单给组长',
                        type:1,
                        area:['540px','460px'],
                        btn:['提交','取消'],
                        content:str,
                        yes:function (index) {
                            let ids = '';
                            $('.tar-i[ised=1]').each(function (k,v) {
                                ids += $(this).attr('value')+',';
                            });

                            if(ids.length<=0){
                                layer.msg('选择组长');
                                return;
                            }

                            $.post('{:url("toGroup")}',{dis_id:data.id,ids:ids},function (res) {
                                if(res.code==1){
                                    layer.msg('操作成功！',{icon:6,time:1000},function () {
                                        tableIn.reload();
                                    });
                                }else{
                                    layer.msg(res.msg);
                                }
                            });

                            layer.close(index);
                        },
                        success:function (lay,index) {
                            $('.tar-i').click(function () {
                                if($(this).attr('ised')=='0'){
                                    $(this).attr('ised','1');

                                }else{
                                    $(this).attr('ised','0');

                                }
                                $(this).find('i').toggle();
                            });
                        }
                    });

                });
            }
            else if(obj.event == 'meet_a'){
                layer.confirm('您确定要接单吗？', function(index){

                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('meeteam')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
            else if(obj.event == 'meet_re'){
                //拒单
                layer.prompt({
                    formType: 2,
                    value: '',
                    title: '请输入拒绝原因',
                    area: ['500px', '250px'] //自定义文本域宽高
                }, function(value, index, elem){

                    if(value.length<=0){
                        layer.msg('请输入原因',{icon:5});
                        return;
                    }

                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('meetre')}",{id:data.id,val:value},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });

                    layer.close(index);
                });
            }
            else if(obj.event == 'meet_info'){
                //拒绝原因
                layer.open({
                    title: '拒绝原因'
                    ,content: data.cause?data.cause:''
                });
            }
            else if(obj.event == 'team_meet'){
                //组长团队
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post('{:url("teamList")}',{dis_id:data.id},function (re) {
                    layer.close(loading);

                    var str = '';

                    str += '<div style="border-bottom: 1px solid #ccc;line-height: 45px;padding-left: 20px;"><button class="layui-btn layui-btn-sm" id="addtr">' +
                        '  <i class="layui-icon">&#xe608;</i> 添加组长' +
                        '</button></div>';

                    str += '<table class="layui-table" style="width: 96%;margin-left: 10px;">';

                    $.each(re.data,function (k,v) {

                        /*str+=   '<tr>' +
                            '<th>'+v.jobs_title+'</th>'+
                            '<td>'+(v.is_lead==1?v.username+'<span style="color: #00B83F">(组长)</span>':v.username)+'</td>'+
                            '<td><a class="layui-btn layui-btn-sm moves" aid="'+v.admin_id+'" did="'+data.id+'">移除</a>' +
                            (v.is_lead==0?'<a class="layui-btn layui-btn-sm lead" aid="'+v.admin_id+'" did="'+data.id+'">领队</a>':'')+
                            '</td>'+
                            '</tr>';*/
                        if(v.is_conf==0){
                            str+=   '<tr>' +
                                '<th>'+v.jobs_title+'</th>'+
                                '<td>'+(v.is_lead==1?v.username+'<span style="color: #00B83F">(组长)</span>':v.username)+'</td>'+
                                '<td>' +
                                    '<a class="layui-btn layui-btn-sm moves" aid="'+v.admin_id+'" did="'+data.id+'">移除</a>'+
                                '</td>'+
                                '</tr>';
                        }else if(v.is_conf==1){
                            str+=   '<tr>' +
                                '<th>'+v.jobs_title+'</th>'+
                                '<td>'+(v.is_lead==1?v.username+'<span style="color: #00B83F">(组长)</span>':v.username)+'</td>'+
                                '<td>' +
                                '</td>'+
                                '</tr>';
                        }else if(v.is_conf==2){
                            str+=   '<tr>' +
                                '<th>'+v.jobs_title+'</th>'+
                                '<td>'+(v.is_lead==1?v.username+'<span style="color: #00B83F">(组长)</span>':v.username)+'</td>'+
                                '<td>' +
                                '<a class="layui-btn layui-btn-warm layui-btn-sm refs" cent="'+v.cause+'" >拒单原因</a>'+
                                '<a class="layui-btn layui-btn-sm moves" aid="'+v.admin_id+'" did="'+data.id+'">移除</a>'+
                                '</td>'+
                                '</tr>';
                        }

                        if(v.children.length>0){
                            $.each(v.children,function (kl,vl) {
                                str+=   '<tr>' +
                                    '<th>|—'+vl.jobs_title+'</th>'+
                                    '<td>'+vl.username+'<span style="color: #00B83F">(组员)</span></td>'+
                                    '<td>' +

                                    '</td>'+
                                    '</tr>';
                            });
                        }

                    });

                    str += '</table>';
                    layer.open({
                        title:'团队人员',
                        type:1,
                        area:['540px','460px'],
                        btn:['关闭'],
                        content:str,
                        success:function (lay,index) {
                            $('#addtr').click(function () {
                                $.post('{:url("Engin/query")}',{is_group:1,gid:'5'},function (dal) {
                                    var str = '<div id="enList" style="margin-left: 20px;">';
                                    str += '<ul class="ps">';
                                    //icon-ls-act
                                    $.each(dal.data, function (k, v) {
                                        if(!sea(re.data,v.admin_id))
                                            str += '<li class="ens" aid="' + v.admin_id + '" isc="0" at="'+v.is_at+'"><span class="icon-ls"><i class="layui-icon layui-icon-ok"></i></span><span>' + v.jobs_title + '：</span><span style="font-size: 16px;">' + v.username + '</span><span style="color: #5fb878">(' + (v.is_at == 0 ? '空闲' : '工作中') + ')</span></li>';
                                    });

                                    str += '</ul>';
                                    str += '</div>';

                                    layer.open({
                                        title: '添加队员',
                                        type: 1,
                                        tipsMore: true,
                                        area: ['540px', '460px'],
                                        btn: ['提交', '取消'],
                                        content: str,
                                        yes: function (index2) {
                                            var ids = '';
                                            $('.ens[isc=1]').each(function () {
                                                ids += $(this).attr('aid') + ',';
                                            });
                                            if (ids.length <= 0) {
                                                layer.msg('请选择人员', {icon: 5});
                                                return;
                                            }

                                            var loading = layer.load(1, {shade: [0.1, '#fff']});

                                            $.post('{:url("addTeam")}', {dis_id: data.id, aid: ids,is_group:1}, function (res) {
                                                layer.close(loading);
                                                if (res.code === 1) {
                                                    layer.msg(res.msg, {time: 1000, icon: 1});
                                                    tableIn.reload();
                                                } else {
                                                    layer.msg(res.msg, {time: 1000, icon: 2});
                                                }
                                                layer.close(index2);
                                                layer.close(index);
                                            });
                                        },
                                        success: function (lay, index) {
                                            $('.ens').click(function () {
                                                var at = $(this).attr('at');
                                                if(at=='1'){
                                                    layer.msg('该人员正在工作中！',{icon:5});
                                                    return;
                                                }
                                                var isc = $(this).attr('isc');
                                                var aid = $(this).attr('aid');
                                                if (isc == '0') {
                                                    $(this).attr('isc', '1');
                                                    $(this).find('.icon-ls').addClass('icon-ls-act');
                                                } else {
                                                    $(this).attr('isc', '0');
                                                    $(this).find('.icon-ls').removeClass('icon-ls-act');
                                                }
                                            });
                                        }
                                    });
                                })
                            });

                            $('.moves').click(function () {
                                var aid = $(this).attr('aid');
                                var did = $(this).attr('did');
                                var tr = $(this).parent().parent();
                                layer.confirm('确认移除该人员吗?', {icon: 3, title:'提示'}, function(rin){
                                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                                    $.post('{:url("remove")}',{dis_id:did,aid:aid},function (re) {
                                        layer.close(loading);
                                        if (re.code === 1) {
                                            layer.msg(re.msg, {time: 1000, icon: 1});
                                            tr.remove();
                                        } else {
                                            layer.msg(re.msg, {time: 1000, icon: 2});
                                        }
                                        layer.close(rin);
                                        layer.close(index);
                                    });
                                });
                            });

                            $('.refs').click(function () {
                                var cent = $(this).attr('cent');
                                layer.open({
                                    title:'拒单原因',
                                    content:cent
                                });
                            });
                        }
                    });

                });
            }
            else if(obj.event == 'del'){
                layer.confirm('您确定要删除任务单吗？(请谨慎操作)', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('del')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });


        $('#add').click(function () {
            location.href = '{:url("addUI")}';
        });
        $('#tak').click(function () {
            location.href = '{:url("meListUI")}';
        });


        function expl(att) {
            let arr = att.split(';');
            let str = '<div>';
            for (al in arr) {
                if(arr[al].length>0){
                    str += '<span><img src="'+arr[al]+'" alt="" onclick="imgeng(this)"></span>';
                }
            }
            str += '</div>';
            return str;
        }


    });

    function imgeng(_t) {
        window.open($(_t).attr('src'));
    }

    function sea(da,id) {
        for (var i=0;i<da.length;i++){
            if(id==da[i].admin_id)
                return true;
        }
        return false;
    }

</script>